<template>
  <div class="todoTaskPage">
    <div class="header">
      <div class="title">
        <span class="icon"></span>
        <span class="txt">待办工作</span>
      </div>
      <!-- <div class="navList">
        <span
          :class="currentNav == index ? 'active' : ''"
          @click="changeNav(index)"
          v-for="(item, index) in navList"
          :key="item.name + index"
          >{{ item.name }}</span
        >
      </div> -->
      <span class="more" @click="moreTask"
        >更多 <i class="sz_arrows_right"></i
      ></span>
    </div>
    <div class="content">
      <div class="edocList">
        <div class="edocItem" @click="toEdocDetail(item)" v-for="(item, index) in nowEdocList" :key="index">
          <span v-if="item.from == 'jk'" class="bgImg type1"></span>
          <span v-if="item.from == 'OA'" class="bgImg type2"></span>
          <span v-if="item.from == 'qf'" class="bgImg type3"></span>
          <span v-if="item.from == 'yj'" class="bgImg type4"></span>
          <span v-if="item.from == 'tg'" class="bgImg type5"></span>
          <span v-if="item.from == 'xf'" class="bgImg type6"></span>
          <p class="title" :title="item.name">{{ item.name }}</p>
          <p class="time">{{ item.type }} | {{item.time}}</p>
        </div>
      </div>
      <!-- <div class="pagination-container">
        <span class="prev-btn" :class="current==1 ? 'nowStep' : ''"  @click="prevPage('prev')"></span>
        <span class="now-btn" :class="current==2 ? 'nowStep' : ''" @click="centerPage('center')"></span>
        <span class="next-btn" :class="current==3 ? 'nowStep' : ''" @click="nextPage('next')"></span>
      </div> -->
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      // navList: [
      //   {
      //     name: "全部",
      //   },
      //   {
      //     name: "上级下发",
      //   },
      //   {
      //     name: "本单位",
      //   },
      // ], //页签列表
      imgList: [
        {
          url: require("../../imgs/bg.png"), //图片地址
          link: "", //跳转地址
        },
        {
          url: require("../../imgs/bg.png"), //图片地址
          link: "", //跳转地址
        },
        {
          url: require("../../imgs/bg.png"), //图片地址
          link: "", //跳转地址
        },
        {
          url: require("../../imgs/bg.png"), //图片地址
          link: "", //跳转地址
        },
      ], //图片列表
      moreLink: "", //更多跳转地址
      edocList: [
      ],
      currentNav: 0, //当前页签
      moreLink: "", //更多跳转地址
      nowEdocList: [], //当前页签下的待办列表
      nowPage: 1, //当前页码
      preStep:'',
      current: 1, //定位
    };
  },
  created() {},
  mounted() {
    this.getEdocData()
  },
  methods: {
    // 获取公文数据
    getEdocData() {
      const code = window.location.href.split('Info=')[1].split('&code=')[1];
      this.axios({
        url: "/seeyon/rest/select/edoc",
        method: "post",
        headers: {
          "Content-Type": "application/json",
          "token":localStorage.getItem("restToken"),
        },
        data: {
          loginName: localStorage.getItem("loginName"),
          code: code
        },
      }).then((res) => {
        console.log("获取待办工作数据", res);
        this.edocList = res.data.data.paddingList;
        this.moreLink = res.data.data.moreUrl;
        this.nowEdocList = this.edocList.slice((this.nowPage - 1) * 6 , this.nowPage * 6) ;
        console.log("当前页签下的待办列表", this.nowEdocList);
      });
    },
    prevPage(t){
      if(this.nowPage == 1){
        return
      }
      this.nowPage -=1
      this.nowEdocList = this.edocList.slice((this.nowPage - 1) * 6 , this.nowPage * 6);
      this.preStep = t
      if(this.nowPage == 1){
        this.current = 1
      }
      else{
        this.current = 2
      }
    },
    nextPage(t){
      if(this.nowPage == Math.ceil(this.edocList.length / 6)){
        return
      }
      this.nowPage +=1
      this.nowEdocList = this.edocList.slice((this.nowPage - 1) * 6 , this.nowPage * 6);
      this.preStep = t
      if(this.nowPage < Math.ceil(this.edocList.length / 6)){
        this.current = 2
      }
      else{
        this.current = 3
      }
    },
    centerPage(t){
      if(this.preStep == 'prev' || this.preStep == ''){
        this.nowPage +=1
        this.nowEdocList = this.edocList.slice((this.nowPage - 1) * 6 , this.nowPage * 6);
        this.preStep = t
        this.current = 2
      }
      else if(this.preStep == 'next'){
        this.nowPage -=1
        this.nowEdocList = this.edocList.slice((this.nowPage - 1) * 6 , this.nowPage * 6);
        this.preStep = t
        this.current = 2
      }
      else{
        return
      }
    },
    // 切换页签
    changeNav(index) {
      this.currentNav = index;
    },
    // 更多工作
    moreTask() {
      // window.open('/seeyon' + this.moreLink, "_blank");
      this.axios({
        url: `/seeyon/oasso.do?method=redirect&loginName=${localStorage.getItem("loginName")}&url=${encodeURIComponent('/seeyon' + this.moreLink)}`,
        method: "get",
        headers: {
          "Content-Type": "application/json",
        },
      }).then((res) => {
        console.log("点击新闻数据", res);
        window.open(res.data, "_blank");
      });
    },
    // 点击工作
    toEdocDetail(item){
      if(item.from == 'OA') {
        this.axios({
          url: `/seeyon/oasso.do?method=redirect&loginName=${localStorage.getItem("loginName")}&url=${encodeURIComponent('/seeyon' + item.url)}`,
          method: "get",
          headers: {
            "Content-Type": "application/json",
          },
        }).then((res) => {
          console.log("点击新闻数据", res);
          window.open(res.data, "_blank");
        });
      } else {
        window.open(item.url, '_blank')
      }
    }
  },
};
</script>
<style lang="less" scoped>
.todoTaskPage {
  width: 100%;
  height: 100%;
  .header {
    height: 50px;
    display: flex;
    align-items: center;
    position: relative;
    .title {
      font-weight: 600;
      font-size: 20px;
      line-height: 50px;
    }
    .navList {
      margin-left: 20px;
      display: flex;
      height: 30px;
      span {
        padding: 0 20px;
        background-color: aliceblue;
        margin: 0 5px;
        border-radius: 15px;
        line-height: 30px;
        cursor: pointer;
      }
      .active {
        background-color: #2c85fb;
        color: #fff;
      }
    }
    .more {
      position: absolute;
      right: 0px;
      cursor: pointer;
      color: #a6a9ad;
      font-size: 14px;
      i{
        font-size: 12px;
      }
    }
  }
  .content {
    height: calc(100% - 50px);
    position: relative;
    .imgList {
      height: 100%;
      width: 300px;
      overflow: hidden;
      margin-right: 10px;
      .imgItem {
        height: 100%;
        float: left;
        img {
          width: 100%;
        }
      }
    }
    .edocList {
      flex: 1;
      display: flex;
      flex-wrap: wrap;
      justify-content: flex-start;
      align-items: flex-start;
      .edocItem {
        width: 100%;
        line-height: 42px;
        height: 42px;
        width: 30%;
        height: 100px;
        background-color: #f8f9fb;
        padding: 15px;
        margin-right: 20px;
        border-radius: 4px;
        position: relative;
        margin-bottom: 10px;
        .bgImg{
          width: 30px;
          height: 30px;
          position: absolute;
          top:20px;
          left: 10px;
          background-image: url(@/imgs/type1.svg);
        }
        .type1{
        background-image: url(@/imgs/type1.svg);
        }
        .type2{
          background-image: url(@/imgs/type2.svg);
        }
        .type3{
          background-image: url(@/imgs/type3.svg);
        }
      .type4{
          background-image: url(@/imgs/type4.svg);
        }
        .type5{
          background-image: url(@/imgs/type5.svg);
        }
        .type6{
          background-image: url(@/imgs/type6.svg);
        }
        .title {
          color: #121213;
          flex: 1;
          text-overflow: ellipsis;
          overflow: hidden;
          white-space: nowrap;
          cursor: pointer;
          text-indent: 30px;
        }
        .time {
          color: #c7ccd1;
          // text-align: right;
          cursor: pointer;
          vertical-align: top;
          white-space: nowrap;      /* 强制文本不换行 */
          overflow: hidden;         /* 超出部分隐藏 */
          text-overflow: ellipsis;  /* 超出部分显示省略号 */
          text-indent: 30px;
        }
      }
      
    }
    .pagination-container{
      width: 100px;
      height: 7px;
      display: flex;
      justify-content: space-around;
      position: absolute;
      bottom: 0px;
      left: 50%;
      transform: translateX(-50%);
      span{
        height: 7px;
        width: 30px;
        background-color: #e7e5e5;
        border-radius: 5px;
        cursor: pointer;
      }
      .nowStep{
        background-color: #0084ff;
      }
    }
  }
}
</style>
<style lang="scss" scoped>
.todoTaskPage {
  .el-table {
    .el-table__header-wrapper {
      .el-table__header {
        .has-gutter {
          .el-table__cell {
            background-color: #f8f8f8;
          }
        }
      }
    }
  }
}
</style>